package API.Collection.Traversal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Consumer;

public class InnerClassAndLambda {
    public static void main(String[] args) {
        Collection<Integer> list = new ArrayList<>();
        for(int i = 1; i <= 10; i++){
            list.add(i);
        }
        // forEach的作用是将List内的对象迭代传递给accept方法，并执行内部语句
        list.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.print(integer + " ");
            }
        });
        System.out.println();
        // 这是lambda表达式，上方的简化版
        list.forEach(integer -> {
            System.out.print(integer + " ");
        });
    }
}
